package iut.acy.cut4u.dao;

import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.logging.Logger;

import iut.acy.cut4u.model.*;

public class ClientDAO extends EntiteDAO {


	static private ClientDAO instance;

	@Override
	public int insert(Object o) throws AlternativeKeyException{
		String request="INSERT INTO CLIENT VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
		System.out.println(request);
		try {
			Client c = (Client) o;
			PreparedStatement ps = DataBaseManager.getInstance().getConnexion().prepareStatement(request);
			System.out.println(ps.toString());
			ps.setInt(1,c.getId());
			ps.setString(2,c.getSexe().toString());
			ps.setString(3, c.getNom());
			ps.setString(4,c.getPrenom());
			ps.setString(5,c.getAdresse());
			ps.setString(6,c.getCodePostal());
			ps.setString(7,c.getVille());
			ps.setString(8,c.getTel());
			String y = c.getDateNaissance().get(GregorianCalendar.YEAR)+"";
			String m = c.getDateNaissance().get(GregorianCalendar.MONTH)+"";
			String d = c.getDateNaissance().get(GregorianCalendar.DAY_OF_MONTH)+"";
			ps.setString(9,y+m+d);
			ps.setString(10,c.getMail());
			System.out.println(ps.toString());
			return ps.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return 0;
	}

	@Override
	public int update(Object o) {
		// A FAIRE
		return 0;
	}

	@Override
	public int delete(Object o, boolean enCascade) {
		// A FAIRE
		return 0;
	}

	static public ClientDAO getInstance() {
		if (instance == null) {
			instance = new ClientDAO();
		}
		return instance;
	}

	public static void main(String[] args) {

	}

}
